package com.lanelu.hencoderplusstudy.view.practice;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.RectF;
import android.util.AttributeSet;
import android.view.View;

import androidx.annotation.Nullable;

/**
 * 画饼图
 */
public class Practice11PieChartView extends View {

    private Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);

    public Practice11PieChartView(Context context) {
        super(context);
    }

    public Practice11PieChartView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    public Practice11PieChartView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        RectF rectF = new RectF(100f, 100f, 500f, 500f);
        paint.setColor(Color.parseColor("#8B008B"));
        canvas.drawArc(rectF, 0, 10, true, paint);
        paint.setColor(Color.parseColor("#D3D3D3"));
        canvas.drawArc(rectF, 12, 10, true, paint);
        paint.setColor(Color.parseColor("#2E8B57"));
        canvas.drawArc(rectF, 24, 50, true, paint);
        paint.setColor(Color.parseColor("#1E90FF"));
        canvas.drawArc(rectF, 76, 178 - 76, true, paint);
        paint.setColor(Color.parseColor("#DC143C"));
        canvas.save();
        canvas.translate(-10f, -10f);
        canvas.drawArc(rectF, 180, 290 - 180, true, paint);
        canvas.restore();
        paint.setColor(Color.parseColor("#FFFF00"));
        canvas.drawArc(rectF, 290, 358 - 290, true, paint);


//        综合练习
//        练习内容：使用各种 Canvas.drawXXX() 方法画饼图
    }
}
